var ObserverMgr = require("ObserverMgr");
module.exports = {
    isInitEvent: false,
    data: {
        userData: {
            name: "UserName",
            id: 0,
            gold: 0,
            sex: 0,
            ip: "0.0.0.0",
        },
        noticeData: {
            radio: "测试广播",// 广播
            notice: "测试公告",// 公告
            payInfo: "测试购买信息",// 购买信息
            agreement: "测试协议",// 协议
        },
        roomData: {
            id: "0",
            playNum: 0,// 玩的第几局

            totalNum: 1,// 总局数
            pao: false,
            hu: false,
            hun: false,
            gang_dai_pao: false,
            dai_zi_pai: false,
            dui7: false,
            zhuang_jia: false,
            gang_kai: false,
        }
    },
    // 设置房间的配置
    setRoomCfg(totalNum, pao, hu,
               hun, gang_dai_pao, dai_zi_pai,
               dui7, zhuang_jia, gang_kai){
        this.data.roomData.totalNum = totalNum;
        this.data.roomData.pao = pao;
        this.data.roomData.hu = hu;
        this.data.roomData.hun = hun;
        this.data.roomData.gang_dai_pao = gang_dai_pao;
        this.data.roomData.dai_zi_pai = dai_zi_pai;
        this.data.roomData.dui7 = dui7;
        this.data.roomData.zhuang_jia = zhuang_jia;
        this.data.roomData.gang_kai = gang_kai;
    },
    setRoomID(id){
        this.data.roomData.id = id;
    },
    getRoomID(){
        return this.data.roomData.id;
    },
    getUserName(){
        return this.data.userData.name.toString();
    },
    getUserGold(){
        return this.data.userData.gold;
    },
    getUserID(){
        return this.data.userData.id.toString();
    },
    initEvent(){
        if (this.isInitEvent) {
            return;
        }
        this.isInitEvent = true;
        ObserverMgr.removeEventListenerWithObject(this);
        // 接收登录消息
        ObserverMgr.addEventListener(MJNetMsg.recv.Login.msg, function (msg, data) {
            this.data.userData.name = data.name;
            this.data.userData.id = data.id;
            this.data.userData.gold = data.gold;
            this.data.userData.sex = data.sex;
            this.data.userData.ip = data.ip;
        }, this);
        // 获取系统配置
        ObserverMgr.addEventListener(MJNetMsg.recv.SysSet.msg, function (msg, data) {
            this.data.noticeData.radio = data.radio;
            this.data.noticeData.notice = data.notice;
            this.data.noticeData.payInfo = data.payInfo;
            this.data.noticeData.agreement = data.agreement;
        }, this);
        // 创建房间成功
        ObserverMgr.addEventListener(MJNetMsg.recv.CreateRoom.msg, function (msg, data) {

        }, this);
    },

}